package com.icoo.apigateway.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.icoo.apigateway.user.mapper.TuserMapper;
import com.icoo.apigateway.user.model.LoginDto;
import com.icoo.apigateway.user.model.Tuser;
import com.icoo.apigateway.user.service.TuserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class TuserServiceImpl implements TuserService {

    @Autowired
    private TuserMapper tuserMapper;

    @Override
    public Integer login(String name, String password, String schema) {
        Tuser tuser = tuserMapper.login(name, password, schema);
        if(tuser != null)
            return tuser.getId();
        return null;
    }

    @Override
    public boolean isExistsName(String name, String schema) {
        return tuserMapper.selectCountByName(name, schema) >= 1;
    }

    @Override
    public int signUp(LoginDto loginDto) {
        Tuser tuser = new Tuser();
        tuser.setUserName(loginDto.getUserName());
        tuser.setUserPassword(loginDto.getUserPassword());
        tuser.setCreateTime(new Date());
        tuser.setUpdateTime(new Date());
        return tuserMapper.insert(tuser, loginDto.getCustomerSchema());
    }
}
